package com.open.pay.wechat.sdk.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Properties;

/**
 * @author zhang kaichao
 */
public class WxUrlConfig {

   private static final Log LOG = LogFactory.getLog(WxUrlConfig.class);

    private static final Properties PROPERTIES = new Properties();

    private WxUrlConfig() {

    }

    static {
        try {
            InputStream is = WxUrlConfig.class.getClassLoader()
                    .getResourceAsStream("wx_url.properties");
            if (is == null) {
                LOG.error("## /WechatPayConfig load wx_url.properties fail.");
                throw new RuntimeException("读取支付模板失败");
            }
            PROPERTIES.load(new InputStreamReader(is, StandardCharsets.UTF_8));
        }
        catch (IOException e) {
            LOG.error("## /WechatPayConfig load wx_url.properties fail:", e);
        }
    }

    public static String readConfig(String key) {
        return (String) PROPERTIES.get(key);
    }
}
